package com.xyy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xyy.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;

/**
 * 用户Mapper接口
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
    
    /**
     * 查询已删除的用户（只返回必要字段）
     */
    @Select("SELECT id, username, nickname, phone, email, gender, status, last_login_time, create_time FROM user WHERE deleted = 1 ORDER BY update_time DESC")
    List<User> selectDeletedUsers();
    
    /**
     * 统计已删除用户的总数
     */
    @Select("SELECT COUNT(*) FROM user WHERE deleted = 1")
    Long countDeletedUsers();
    
    /**
     * 根据ID查询已删除的用户（用于恢复操作）
     */
    @Select("SELECT * FROM user WHERE id = #{userId} AND deleted = 1")
    User selectDeletedUserById(Long userId);
    
    /**
     * 恢复已删除的用户（设置deleted=0）
     */
    @Update("UPDATE user SET deleted = 0, update_time = NOW() WHERE id = #{userId} AND deleted = 1")
    int restoreUserById(Long userId);
}